
from code import InteractiveInterpreter, InteractiveConsole
from PyQt4.QtCore import QObject, SIGNAL

class SCInterpreter(QObject,InteractiveConsole):
    '''Runs an instance interpreter.
    '''
    def __init__(self,parent=None,locals=None):
        InteractiveConsole.__init__(self,locals)
        QObject.__init__(self,parent)
    
    def runsource(self,source,file='<input>',atype='single'):
        try:
            return InteractiveConsole.runsource(self,source,file,atype)
        except SystemExit:
            print '\nPlease use the GUI to exit!\n'
            return False
    
    def execfile(self, filename):
        """Exec filename"""
        source = open(filename, 'r').read()
        try:
            try:
                name = filename.encode('ascii')
            except UnicodeEncodeError:
                name = '<executed_script>'
            code = compile(source, name, "exec")
        except (OverflowError, SyntaxError):
            InteractiveConsole.showsyntaxerror(self, filename)
        else:
            self.runcode(code)
